package com.astoolkit.workflow.task.spark
{
	import com.astoolkit.workflow.BasePipelineTask;
	
	import mx.effects.Effect;
	import mx.events.EffectEvent;
	
	import spark.effects.Animate;

	[DefaultProperty("animation")]
	public class ExecuteSparkAnimation extends BasePipelineTask
	{
		public var animation : Effect;
		public var blocking : Boolean = true;
		
		override public function begin(inRetain:Boolean=false):void
		{
			super.begin(inRetain);
			if( !animation )
			{
				fail( "No animation set." );
				return;
			}
			
			if( animation.target == null )
				animation.target = _pipelineData;
			animation.play();
			if( blocking )
				addSuspendableListener( animation, EffectEvent.EFFECT_END, onAnimationEnd );
			else
				complete();
		}
		
		private function onAnimationEnd( inEvent : EffectEvent ) : void
		{
			complete();
		}
	}
}